package cn.imvc.app.models;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import cn.imvc.app.entities.PointsToMoney;
import cn.imvc.app.repositories.DealerLevelRepository;
import cn.imvc.app.repositories.PointsToMoneyRepository;
import cn.imvc.core.ModelUtil;
import cn.imvc.data.domain.ViewRequest;
@Service
public class PointsToMoneyModelImpl implements PointsToMoneyModel{

	@Autowired
	PointsToMoneyRepository pointsToMoneyRepository;
	
	public Page<PointsToMoney> find(ViewRequest viewRequest) {
		return pointsToMoneyRepository.findAll(ModelUtil.OrderByIdDesc(viewRequest));
	}

	public PointsToMoney save(PointsToMoney pointsToMoney ) {
		return pointsToMoneyRepository.saveAndFlush(pointsToMoney);
	}

	public PointsToMoney get(int id) {
		
		return pointsToMoneyRepository.getOne(id);
	}

	public PointsToMoney update(int id,PointsToMoney pointsToMoney) {
		PointsToMoney loadPointsToMoney = pointsToMoneyRepository.getOne(id);
		BeanUtils.copyProperties(pointsToMoney, loadPointsToMoney, new String[]{"id"});
		return pointsToMoneyRepository.saveAndFlush(loadPointsToMoney);
		
	}

}
